#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //初始化Splider
    ui->horizontalSlider->setValue(0);
    ui->horizontalSlider->setMinimum(0);
    ui->horizontalSlider->setMaximum(100);
    ui->horizontalSlider->setSingleStep(10);

    //绑定槽函数，建立快捷键
    QShortcut* shortcur1 = new QShortcut(this);
    shortcur1->setKey(QKeySequence("-"));
    connect(shortcur1,&QShortcut::activated,this,&Widget::subValue);

    QShortcut* shortcur2 = new QShortcut(this);
    shortcur2->setKey(QKeySequence("="));
    connect(shortcur1,&QShortcut::activated,this,&Widget::addValue);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText(QString("当前值为: ") + QString::number(value));
}

void Widget::subValue()
{
    ui->horizontalSlider->setValue(ui->horizontalSlider->value() - 10);
}

void Widget::addValue()
{
    ui->horizontalSlider->setValue(ui->horizontalSlider->value() + 10);
}
